package com.ithiema.write;

import com.alibaba.excel.EasyExcel;
import com.ithiema.pojo.Employee;
import com.ithiema.utils.TestFileUtil;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/*
    根据模版写数据
 */
public class FillWriter {
    @Test
    public void testFill(){
        String fileName = TestFileUtil.getPath() +System.currentTimeMillis()+ "按照模版写数据.xlsx";
        String templateFileName = TestFileUtil.getPath() +"模版.xlsx";
        EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(data(20));
    }


    // 准备测试数据的方法
    private List<Employee> data(int i) {
        List<Employee> list = new ArrayList<>();
        for (int j = 1; j <= i; j++) {
            list.add(new Employee(j,"测试数据"+j,6.6*j,new Date()));
        }
        return list;
    }
}
